package eyrolles;


import eyrolles.modele.EyrollesPlugin;
import eyrolles.modele.ModeleInterface;
import javax.servlet.ServletContext;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author scriptoff
 */
public class GenericAction extends Action {
    public ModeleInterface getModele() {
         ServletContext sC = getServlet().getServletContext();
         return (ModeleInterface)sC.getAttribute(EyrollesPlugin.PROPERTIES);
    }
    public Employe convertEmployeForm2Employe(ActionForm form) throws NumberFormatException {
        EmployeForm eForm = (EmployeForm)form;
        Employe emp = new Employe();
        emp.setPassword(eForm.getPassword());
        emp.setRoleid(Integer.parseInt(eForm.getRoleid()));
        emp.setName(eForm.getName());
        emp.setPhone(eForm.getPhone());
        emp.setEmail(eForm.getEmail());
        emp.setDepid(Integer.parseInt(eForm.getDepid()));
        emp.setUsername(eForm.getUsername());
        return emp;
    }
    public EmployeForm convertEmploye2EmployeForm(Employe emp) throws NumberFormatException {
        EmployeForm eForm = new EmployeForm();
        eForm.setPassword(emp.getPassword());
        eForm.setRoleid( Integer.toString(emp.getRoleid()) ) ;
        eForm.setName(emp.getName());
        eForm.setPhone(emp.getPhone());
        eForm.setEmail(emp.getEmail());
        eForm.setDepid(Integer.toString(emp.getRoleid()));
        eForm.setUsername(emp.getUsername());
        return eForm;
    }
}
